<?php

    namespace Logistics\Controller;

    use Common\Controller\AdminbaseController;

    class AdminFinanceController extends AdminbaseController {

        protected $m_logistics_bill,$m_card,$m_recharge,$m_card_sale,$m_logistics,$m_sale,$m_user,$m_refund;

        function _initialize() {
            parent::_initialize();
            $this->m_logistics_bill= D("Logistics/LogisticsBill");
            $this->m_card = D("Admin/Card");
            $this->m_recharge = D("Admin/Recharge");
            $this->m_card_sale = D("Sale/CardSale");
            $this->m_card_sale_cancel = D("Sale/CardSaleCancel");
            $this->m_logistics = D("Admin/Logistics");
            $this->m_sale = D("Admin/Sale");
            $this->m_sale_manager = D("Admin/SaleManager");
            $this->m_user = D("Common/Users");
            $this->m_refund= D("Admin/Refund");

            $logistics_manager_list = $this->m_logistics->get_list('manager_id = 0');
            $this->assign("logistics_manager_list",$logistics_manager_list);
        }

        /**
         * 搜索下级分类
         */
        public function get_logistics_by_manager(){
            $s_m_rid = intval(I("request.s_m_rid"));
            if($s_m_rid>0){
                $logistics_list = $this->m_logistics->get_list("manager_id=".$s_m_rid);
                die(json_encode(['code'=>0,'data'=>$logistics_list]));
            }else{
                die(json_encode(['code'=>-1,'data'=>'参数有误']));
            }
        }

        /**
         * 本部卡充值明细
         */
        public function recharge_detail(){
            $where = array();
            if(is_manager($this->user_model)){ //管理员进入


                $s_m_rid = I("request.s_m_rid");
                $this->assign("s_m_rid",$s_m_rid);

                $s_rid = I("request.s_rid");
                $this->assign("s_rid",$s_rid);

                $sale_list = $this->m_sale->select();
                $this->assign("sale_list",$sale_list);

                $s_sale_id = I("request.s_sale_id");
                $this->assign("s_sale_id",$s_sale_id);

                $admin_list = $this->m_user->where(array('model'=>array('in','2,3,6,7')))->select();
                $this->assign("admin_list",$admin_list);

                $s_admin_id = I("request.s_admin_id");
                $this->assign("s_admin_id",$s_admin_id);
                if($s_m_rid > 0){
                    $logistics_list = $this->m_logistics->get_list("manager_id=".$s_m_rid);
                }else{
                    $logistics_list = $this->m_logistics->get_list();
                }
                $this->assign("logistics_list",$logistics_list);

                if(intval($s_m_rid)>0 && empty($s_rid)){
                    $rids[] = $s_m_rid;
                    $logistics_list = $this->m_logistics->get_list("manager_id=".$s_m_rid);
                    if(!empty($logistics_list)){
                        $ids = array_column($logistics_list,'id');
                        $rids = array_merge($rids,$ids);
                    }
                    $where = ['r.lid'=>['IN',$rids]];
                }elseif(!empty($s_rid)){
                    $where["r.lid"] = $s_rid;
                }

                if(!empty($s_sale_id)){
                    $where["r.sale_id"] = $s_sale_id;
                }
                if(!empty($s_admin_id)){
                    $where["r.uid"] = $s_admin_id;
                }
            }else if ($this->user_model == 3){  // 消费机构
                $lid = 1;
                $sale_id = get_sale_id();
                $where = array("r.lid"=>$lid,'r.sale_id'=>$sale_id);

            }else if ($this->user_model == 6){  // 上级消费机构
                $lid = 1;
                $sale_ids = array();
                $sales = $this->m_sale->where(array('sale_manager_id'=>session("ADMIN_ID")))->find();
                if($sales) foreach ($sales as $_key => $_row) {
                    $sale_ids[] = $_row['id'];
                }

                $where = array("r.lid"=>$lid,"r.sale_id"=>array("IN",$sale_ids));
            }else{
                // $card_ids = get_card_id_by_logistics();
                // $where = array("r.rid"=>array('in',$card_ids));
                $lids = get_logistics_ids();
                if ($lids) {
                    $where = array('r.lid'=>array('in',$lids));
                }
            }

            $s_start_time = I("s_start_time");
            $s_end_time = I("s_end_time");

            if(empty($s_start_time)){
                $s_start_time = strtotime(date("Y-m-d 00:00:00")." -7 day");
            }else{
                $s_start_time = strtotime($s_start_time.":00");
            }
            if(empty($s_end_time)){
                $s_end_time = time();
            }else{
                $s_end_time = strtotime($s_end_time.":59");
            }
            $this->assign("s_start_time",$s_start_time);
            $this->assign("s_end_time",$s_end_time);
            $where["r.create_time"]=array("BETWEEN",array($s_start_time,$s_end_time));
            $where["r.model"] = 2;
            $where['r.status'] = 2;

            //卡号筛选
            $s_card_number = I("s_card_number");
            if(!empty($s_card_number)){
                $where["c.number"] = array("like","%$s_card_number%");
                $this->assign("s_card_number",$s_card_number);
            }

            $count=$this->m_recharge->alias("r")->join("bdt_card c ON c.id = r.rid","inner")->where($where)->count();

            $page = $this->page($count, 15);
            $list = $this->m_recharge->get_card_list($where,"create_time DESC",$page->firstRow, $page->listRows);

            if(!empty(I('s_download'))){
                $export_list =  $this->m_recharge->get_card_list($where,"create_time DESC",0, $count);
                if(I('s_download') == 1){
                    $export_title = array(
                        'create_time'=>'创建日期',
                        'number'=>'流水号',
                        'card_number'=>'会员卡号',
                        'vip_name'=>'会员卡号',
                        'vip_phone'=>'会员卡号',
                        'vip_plate_number'=>'会员卡号',
                        'recharge_type'=>'充值类型',
                        'recharge_status'=>'充值状态',
                        'pay_type'=>'支付类型',
                        'price'=>'充值金额',
                        'general_price'=>'一号物流奖励金额',
                        'self_price'=>'充值奖励金额',
                        'rebate_price'=>'充值返利金额',
                        'active_price'=>'开卡费',
                        'before_balance'=>'充值前余额',
                        'logistics_name'=>'充值机构',
                        'logistics_name2'=>'卡片所属机构',
                        'vip_name'=>'会员姓名',
                        'vip_phone'=>'会员手机',
                        'vip_plate_number'=>'会员车牌',
                        'user_nicename'=>'操作员姓名',
                        'user_phone'=>'操作员手机',
                        'desc'=>'充值描述',
                    );
                    foreach($export_list AS &$item){
                        $item['recharge_type'] = $item['sale_id']?'消费机构充值':'物流充值';
                        $item['recharge_status'] = $item['status']=='2'?'成功':'未完成';
                        $item['pay_type'] = '卡帐户转账';
                        // $item['logistics_name2'] = $item['cl_logistics_name'];
                        $item['logistics_name2'] = $item['logistics_name'];
                        $item['logistics_name'] = $item['sale_id']?$item['sale_name']:$item['logistics_name'];
                    }
                    $excel = new \Common\Lib\excel();
                    $excel->export_data('本部卡充值账单明细',$export_title,$export_list);exit;
                }elseif(I('s_download') == 2){
                    $html_data ='<table  border="1"  cellpadding="4">
                    <thead>
                    <tr bgcolor="#cccccc">
                        <th>创建日期</th>
                        <th>流水号</th>
                        <th>会员卡号</th>
                        <th>会员姓名</th>
                        <th>会员手机号</th>
                        <th>会员车牌号</th>
                        <th>充值金额	</th>
                        <th>一号物流奖励金额	</th>
                        <th>充值奖励金额	</th>
                        <th>充值返利金额	</th>
                        <th>充值前余额	</th>
                        <th>充值机构  </th>
                        <th>卡片所属机构	</th>
                        <th>会员姓名   </th>
                        <th>会员手机   </th>
                        <th>会员车牌	</th>
                        <th>操作员姓名</th>
                    </tr>
                    </thead>
                    <tbody>';
                    $list =  $this->m_recharge->get_card_list($where,"create_time DESC",0, $count);
                    foreach($list AS $item){
                        $item['logistics_name2'] = $item['logistics_name'];
                        $item['logistics_name'] = $item['sale_id']?$item['sale_name']:$item['logistics_name'];

                        $html_data .= ' <tr>
                            <td><b>'.$item['create_time'].'</b></td>
                            <td>'.$item['number'].'</td>
                            <td>'.$item['card_number'].'</td>
                            <td>'.$item['vip_name'].'</td>
                            <td>'.$item['vip_phone'].'</td>
                            <td>'.$item['vip_plate_number'].'</td>
                            <td>'.$item['price'].'</td>
                            <td>'.$item['general_price'].'</td>
                            <td>'.$item['self_price'].'</td>
                            <td>'.$item['rebate_price'].'</td>
                            <td>'.$item['before_balance'].'</td>
                            <td>'.$item['logistics_name'].'</td>
                            <td>'.$item['logistics_name2'].'</td>
                            <td>'.$item['vip_name'].'</td>
                            <td>'.$item['vip_phone'].'</td>
                            <td>'.$item['vip_plate_number'].'</td>
                            <td>'.$item['user_nicename'].'</td>
                        </tr>';
                    }
                    $html_data .=" </tbody></table>";
                    $pdf = new \Common\Lib\pdf();
                    $pdf->export_pdf('recharge_detail',$html_data);exit;
                }
            }

            $this->assign("user_model",$this->user_model);
            $this->assign("page", $page->show('Admin'));
            $this->assign("list",$list);
            $this->display();
        }

        /**
         * 本部卡消费账单明细
         */
        public function sale_detail(){
            if($this->user_model == 3){ //消费机构
                $sid = get_sale_id();
                $where = array("s.sale_id"=>$sid);

            }elseif(is_manager($this->user_model)){
                $s_rid = I("request.s_rid");
                $this->assign("s_rid",$s_rid);
                $s_smid = I("request.s_smid");
                $this->assign("s_smid",$s_smid);
                $s_sid = I("request.s_sid");
                $this->assign("s_sid",$s_sid);

                $s_m_rid = I("request.s_m_rid");
                $this->assign("s_m_rid",$s_m_rid);
                if($s_m_rid > 0){
                    $logistics_list = $this->m_logistics->get_list("manager_id=".$s_m_rid);
                }else{
                    $logistics_list = $this->m_logistics->get_list();
                }
                $this->assign("logistics_list",$logistics_list);

                $sale_list = $this->m_sale->select();
                $this->assign("sale_list",$sale_list);
                $sale_manager_list = $this->m_sale_manager->select();
                $this->assign("sale_manager_list",$sale_manager_list);
                $where = array();

                if(intval($s_m_rid)>0 && empty($s_rid)){
                    $rids[] = $s_m_rid;
                    $logistics_list = $this->m_logistics->get_list("manager_id=".$s_m_rid);
                    if(!empty($logistics_list)){
                        $ids = array_column($logistics_list,'id');
                        $rids = array_merge($rids,$ids);
                    }
                    $where = ['s.lid'=>['IN',$rids]];
                }elseif(!empty($s_rid)){
                    $where["s.lid"] = $s_rid;
                }

                if(!empty($s_smid)){
                    $where["s.sale_manager_id"] = $s_smid;
                }
                if(!empty($s_sid)){
                    $where["s.sale_id"] = $s_sid;
                }
            }elseif($this->user_model == 6){    //消费机构管理员
                $users_obj= M("Users");
                $user=$users_obj->where(array('id'=>session("ADMIN_ID")))->find();
                $where["s.sale_manager_id"] = $user["organize_id"];
            }else{
                // $card_list_id = get_card_id_by_logistics();
                // $where = array("s.cid"=>array("IN",$card_list_id));
                $lids = get_logistics_ids();
                if ($lids) {
                    $where = array('s.lid'=>array('in',$lids));
                }
            }

            //卡号筛选
            $s_card_number = I("s_card_number");
            if(!empty($s_card_number)){
                $where["s.card_number"] = array("like","%$s_card_number%");
                $this->assign("s_card_number",$s_card_number);
            }

            //时间筛选
            $s_start_time = I("s_start_time");
            $s_end_time = I("s_end_time");
            if(empty($s_start_time)){
                $s_start_time = strtotime(date("Y-m-d 00:00:00")." -7 day");
            }else{
                $s_start_time = strtotime($s_start_time.":00");
            }
            if(empty($s_end_time)){
                $s_end_time = time();
            }else{
                $s_end_time = strtotime($s_end_time.":59");
            }
            $this->assign("s_start_time",$s_start_time);
            $this->assign("s_end_time",$s_end_time);
            $where["s.create_time"]=array("BETWEEN",array($s_start_time,$s_end_time));

            $count=$this->m_card_sale->alias("s")->where($where)->count();
            $page = $this->page($count, 15);
            $list = $this->m_card_sale->get_list($where,"s.create_time DESC",$page->firstRow, $page->listRows);
            
            if(!empty(I('s_download'))) {
                if (I('s_download') == 1) {
                    $export_title = array(
                        'create_time' => '消费时间',
                        'top_logistics_name' => '上级卡片所属机构',
                        'logistics_name' => '卡片所属机构',
                        'top_sale_name' => '上级消费机构',
                        'sale_name' => '消费机构',
                        'number' => '账单号',
                        'card_number' => '会员卡号',
                        'vip_name' => '会员名称',
                        'vip_phone' => '会员手机号',
                        'vip_plate_number' => '会员车牌号',
                        'bill_type' => '账单类型',
                        'bill_status' => '账单状态',
                        'pay_type' => '支付类型',
                        'price_pay' => '账单支付金额',
                        'general_point' => '一号物流奖励积分',
                        'self_point' => '自营奖励积分',
                        'plus_point' => '剩余积分',
                        'plus_price' => '剩余金额',

                        'user_nicename' => '销售姓名',
                        'user_phone' => '销售电话',
                        'goods_name' => '商品名称',
                        'goods_unit_price' => '产品单价',
                        'goods_num' => '商品数量',
                        'goods_price' => '商品总价',
                        'dis_price' => '优惠金额',
                        'price' => '账单支付金额',
                        'desc' => '描述',
                    );
                    $list = $this->m_card_sale->get_list($where, "create_time DESC", 0, $count);
                    foreach ($list AS &$item) {
                        $item['bill_type'] = '一号物流卡消费';
                        $item['bill_status'] = '成功';
                        $item['pay_type'] = '卡帐户转账';
                        $item['price_pay'] = $item['price'];
                        $item['top_logistics_name'] ="";
                        $item['top_sale_name'] ="";
                        if(isset($item['l_m_id']) && !empty($item['l_m_id'])){
                            $card_manager = D("Admin/Logistics")->where("id=" . $item['l_m_id'])->find();
                            $item['top_logistics_name'] = $card_manager['logistics_name'];
                        }

                        if(isset($item['sale_manager_id']) && !empty($item['sale_manager_id'])) {
                            $card_manager = D("Admin/Sale")->where("id=" . $item['sale_manager_id'])->find();
                            $item['top_sale_name'] = $card_manager['sale_name'];
                        }
                    }
                    $excel = new \Common\Lib\excel();
                    $excel->export_data('本部卡消费账单明细', $export_title, $list);
                    exit;
                } elseif (I('s_download') == 2) {
                    $html_data = '<table  border="1"  cellpadding="4">
                    <thead>
                    <tr  bgcolor="#cccccc">
                        <th>消费时间</th>
                        <th>账单号</th>
                        <th>会员卡号</th>
                        <th>账单总价    </th>
                        <th>一号物流奖励积分    </th>
                        <th>自营奖励积分  </th>
                        <th>剩余积分    </th>
                        <th>剩余金额    </th>
                        <th>卡片所属机构  </th>
                        <th>销售姓名</th>
                    </tr>
                    </thead>
                    <tbody>';
                    $list = $this->m_card_sale->get_list($where, "create_time DESC", 0, $count);
                    foreach ($list AS $item) {
                        $html_data .= ' <tr>
                            <td><b>' . $item['create_time'] . '</b></td>
                            <td>' . $item['number'] . '</td>
                            <td>' . $item['card_number'] . '</td>
                            <td>' . $item['price'] . '</td>
                            <td>' . $item['general_point'] . '</td>
                            <td>' . $item['self_point'] . '</td>
                            <td>' . $item['plus_point'] . '</td>
                            <td>' . $item['plus_price'] . '</td>
                            <td>' . $item['logistics_name'] . '</td>
                            <td>' . $item['user_nicename'] . '</td>
                        </tr>';
                    }
                    $html_data .= " </tbody></table>";
                    $pdf = new \Common\Lib\pdf();
                    $pdf->export_pdf('sale_detail', $html_data);
                    exit;
                }
            }

            $summary = array(
                'count'=>0,
                'goods_price'=>0,
                'dis_price'=>0,
                'price'=>0,
            );
            foreach ($list as $_key => $_row) {
                $summary['count'] += 1;
                $summary['goods_price'] += $_row['goods_price'];
                $summary['dis_price'] += $_row['dis_price'];
                $summary['price'] += $_row['price'];
                $summary['goods_num'] += $_row['goods_num'];
                if ($_row['is_oil'] == '1') {
                    $summary['oil_num'] += $_row['goods_num'];
                }else{
                    $summary['not_oil_num'] += $_row['goods_num'];
                }
            }

            $this->assign("user_model",$this->user_model);
            $this->assign("page", $page->show('Admin'));
            $this->assign("list",$list);
            $this->assign("summary",$summary);
            $this->display();
        }

        /**
         * 本部卡退款明细
         * @return [type] [description]
         */
        public function refund_detail(){

            $where = array();
            $lid = get_logistics_id();
            if($lid){
                $lids = get_logistics_ids();
                $where['r.lid'] = array('in',$lids);
            }
            $s_m_rid = I("request.s_m_rid");
            $this->assign("s_m_rid",$s_m_rid);
            if($s_m_rid > 0){
                $logistics_list = $this->m_logistics->get_list("manager_id=".$s_m_rid);
            }else{
                $logistics_list = $this->m_logistics->get_list();
            }
            $this->assign("logistics_list",$logistics_list);

            $s_rid = I("request.s_rid");
            $this->assign("s_rid",$s_rid);

            if(intval($s_m_rid)>0 && empty($s_rid)){
                $rids[] = $s_m_rid;
                $logistics_list = $this->m_logistics->get_list("manager_id=".$s_m_rid);
                if(!empty($logistics_list)){
                    $ids = array_column($logistics_list,'id');
                    $rids = array_merge($rids,$ids);
                }
                $where = ['r.lid'=>['IN',$rids]];
            }elseif(!empty($s_rid)){
                $where["r.lid"] = $s_rid;
            }

            $admin_list = $this->m_user->where(array('model'=>array('in','2,3,6,7')))->select();
            $this->assign("admin_list",$admin_list);

            $s_admin_id = I("request.s_admin_id");
            $this->assign("s_admin_id",$s_admin_id);
            if(!empty($s_admin_id)){
                $where["r.uid"] = $s_admin_id;
            }

            $s_start_time = I("s_start_time");
            $s_end_time = I("s_end_time");
            if(empty($s_start_time)){
                $s_start_time = strtotime(date("Y-m-d 00:00:00")." -7 day");
            }else{
                $s_start_time = strtotime($s_start_time.":00");
            }
            if(empty($s_end_time)){
                $s_end_time = time();
            }else{
                $s_end_time = strtotime($s_end_time.":59");
            }
            $this->assign("s_start_time",$s_start_time);
            $this->assign("s_end_time",$s_end_time);
            $where["r.create_time"]=array("BETWEEN",array($s_start_time,$s_end_time));

            //卡号筛选
            $s_card_number = I("s_card_number");
            if(!empty($s_card_number)){
                $where["c.number"] = array("like","%$s_card_number%");
                $this->assign("s_card_number",$s_card_number);
            }

            $where['r.model'] = 2;
            $count=$this->m_refund->alias("r")->join("bdt_card c ON c.id = r.rid","LEFT")->where($where)->count();

            $page = $this->page($count, 15);
            $list =$this->m_refund->alias("r")->field("r.*,l.logistics_name,c.number AS card_number,u.user_nicename,u.user_phone")->where($where)
                ->join("bdt_card c ON c.id = r.rid","LEFT")
                ->join("bdt_logistics l ON l.id = r.lid","LEFT")
                ->join("bdt_users u ON u.id = r.uid","LEFT")
                ->order("create_time DESC")
                ->limit($page->firstRow , $page->listRows)
                ->select();



            if(I('s_download') == 1){
                $export_title = array(
                    'number'=>'账单号',
                    'card_number'=>'卡号',
                    'price'=>'退款金额',
                    'before_balance'=>'退款前余额',
                    'user_nicename'=>'操作员',
                    'user_phone'=>'操作员手机号',
                    'create_time'=>'创建时间',
                );
                $excel = new \Common\Lib\excel();
                $excel->export_data('卡片退款账单',$export_title,$list);exit;
            }
            foreach($list AS &$item){
                $item["create_time"] = date("Y-m-d H:i:s",$item["create_time"]);
            }
            $this->assign("page", $page->show('Admin'));
            $this->assign("list",$list);
            $this->display();
            
        }

        /**
         * 取消的本部卡消费账单明细
         */
        public function sale_detail_cancel(){
            if(is_manager($this->user_model)){
                $s_rid = I("request.s_rid");
                $this->assign("s_rid",$s_rid);
                $s_smid = I("request.s_smid");
                $this->assign("s_smid",$s_smid);
                $s_sid = I("request.s_sid");
                $this->assign("s_sid",$s_sid);
                $logistics_list = $this->m_logistics->get_list();
                $this->assign("logistics_list",$logistics_list);
                $sale_list = $this->m_sale->select();
                $this->assign("sale_list",$sale_list);
                $sale_manager_list = $this->m_sale_manager->select();
                $this->assign("sale_manager_list",$sale_manager_list);
                $where = array();
                if(!empty($s_rid)){
                    $where["s.lid"] = $s_rid;
                }
                if(!empty($s_smid)){
                    $where["s.sale_manager_id"] = $s_smid;
                }
                if(!empty($s_sid)){
                    $where["s.sale_id"] = $s_sid;
                }
            }

            //卡号筛选
            $s_card_number = I("s_card_number");
            if(!empty($s_card_number)){
                $where["s.card_number"] = array("like","%$s_card_number%");
                $this->assign("s_card_number",$s_card_number);
            }

            //时间筛选
            $s_start_time = I("s_start_time");
            $s_end_time = I("s_end_time");
            if(empty($s_start_time)){
                $s_start_time = strtotime(date("Y-m-d 00:00:00")." -7 day");
            }else{
                $s_start_time = strtotime($s_start_time.":00");
            }
            if(empty($s_end_time)){
                $s_end_time = time();
            }else{
                $s_end_time = strtotime($s_end_time.":59");
            }
            $this->assign("s_start_time",$s_start_time);
            $this->assign("s_end_time",$s_end_time);
            $where["s.create_time"]=array("BETWEEN",array($s_start_time,$s_end_time));


            $count=$this->m_card_sale_cancel->alias("s")->where($where)->count();
            $page = $this->page($count, 15);
            $list = $this->m_card_sale_cancel->get_list($where,"s.create_time DESC",$page->firstRow, $page->listRows);

            if(!empty(I('s_download'))) {
                if (I('s_download') == 1) {
                    $export_title = array(
                        'create_time' => '消费时间',
                        'logistics_name' => '卡片所属机构',
                        'sale_name' => '消费机构',
                        'number' => '账单号',
                        'card_number' => '会员卡号',
                        'bill_type' => '账单类型',
                        'bill_status' => '账单状态',
                        'pay_type' => '支付类型',
                        'price_pay' => '账单支付金额',
                        'general_point' => '一号物流奖励积分',
                        'self_point' => '自营奖励积分',
                        'plus_point' => '剩余积分',
                        'plus_price' => '剩余金额',
                        'car_code' => '绑定车牌号',

                        'user_nicename' => '销售姓名',
                        'user_phone' => '销售电话',
                        'goods_name' => '商品名称',
                        'goods_num' => '商品数量',
                        'goods_price' => '商品总价',
                        'dis_price' => '优惠金额',
                        'price' => '账单支付金额',
                        'desc' => '描述',
                    );
                    $list = $this->m_card_sale_cancel->get_list($where, "create_time DESC", 0, $count);
                    foreach ($list AS &$item) {
                        $item['bill_type'] = '一号物流卡消费';
                        $item['bill_status'] = '成功';
                        $item['pay_type'] = '卡帐户转账';
                        $item['price_pay'] = $item['price'];
                    }
                    $excel = new \Common\Lib\excel();
                    $excel->export_data('本部卡消费账单明细', $export_title, $list);
                    exit;
                } elseif (I('s_download') == 2) {
                    $html_data = '<table  border="1"  cellpadding="4">
                    <thead>
                    <tr  bgcolor="#cccccc">
                        <th>消费时间</th>
                        <th>账单号</th>
                        <th>会员卡号</th>
                        <th>账单总价	</th>
                        <th>一号物流奖励积分	</th>
                        <th>自营奖励积分	</th>
                        <th>剩余积分	</th>
                        <th>剩余金额	</th>
                        <th>卡片所属机构	</th>
                        <th>销售姓名</th>
                    </tr>
                    </thead>
                    <tbody>';
                    $list = $this->m_card_sale_cancel->get_list($where, "create_time DESC", 0, $count);
                    foreach ($list AS $item) {
                        $html_data .= ' <tr>
                            <td><b>' . $item['create_time'] . '</b></td>
                            <td>' . $item['number'] . '</td>
                            <td>' . $item['card_number'] . '</td>
                            <td>' . $item['price'] . '</td>
                            <td>' . $item['general_point'] . '</td>
                            <td>' . $item['self_point'] . '</td>
                            <td>' . $item['plus_point'] . '</td>
                            <td>' . $item['plus_price'] . '</td>
                            <td>' . $item['logistics_name'] . '</td>
                            <td>' . $item['user_nicename'] . '</td>
                        </tr>';
                    }
                    $html_data .= " </tbody></table>";
                    $pdf = new \Common\Lib\pdf();
                    $pdf->export_pdf('sale_detail', $html_data);
                    exit;
                }
            }
            
            $this->assign("user_model",$this->user_model);
            $this->assign("page", $page->show('Admin'));
            $this->assign("list",$list);
            $this->display();
        }
    }